package com.lagou.mall.esflow.client;


import com.alibaba.fastjson.JSONObject;
import java.util.Optional;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@NoArgsConstructor
@AllArgsConstructor

public class Binlog {

    private String database;
    private String table;
    private String type;
    private Long ts;
    private Long xid;
    private Boolean commit;
    private JSONObject data;
    private JSONObject old;


    public Optional<String> get(String key) {
        return data.keySet().stream().filter(column -> column.equals(key)).findAny()
                .map(column -> data.get(column).toString());
    }


    public JSONObject getData() {
        return data;
    }

    public JSONObject getOld() {
        return old;
    }

    public void setData(JSONObject data) {
        this.data = data;
    }

    public void setOld(JSONObject old) {
        this.old = old;
    }
}
